﻿using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Jungle.Code.DAL;
using Jungle.Code.Utils;
using Jungle.News;

public partial class updateNews : UserControl
{

    string ImgUrl;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request["id_news"] != null)
        {
            LoadData();
        }
    }

    protected void Update(object sender, EventArgs e)
    {
        if (fu_Img.HasFile)
        {
            string fname = "/UserFiles/Images/News/" + Session.SessionID + "_" + fu_Img.FileName;
            fu_Img.SaveAs(Server.MapPath(fname));

            ImgUrl = fname;
        }

        NewObject n = new NewObject();
        n.NewId = Convert.ToInt32(Request["id_news"]);
        n.GetById();

        n.Title = newsTitle.Text.Trim();
        n.Description = content.Value.Trim();
        n.Img = ImgUrl;
        n.Update();

        Response.Redirect("~/Admin/Modules.aspx?mod=News&cmd=News");
        
    }

    protected void LoadData()
    {
        NewObject n = new NewObject();
        n.NewId = Convert.ToInt32(Request["id_news"]);
        n.GetById();

        newsTitle.Text = n.Title;
        content.Value = n.Description;
        img_Img.ImageUrl = "~/" + n.Img;
        ImgUrl = n.Img;      
    }
}
